package com.huishu.goods.controller;


import com.alibaba.fastjson.JSON;
import com.huishu.commons.pojo.Result;
import com.huishu.goods.pojo.dto.GiveDTO;
import com.huishu.goods.pojo.dto.GivePageDTO;
import com.huishu.goods.service.GiveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author generator@ljj
 * @since 2023-04-19
 */
@RestController
@RequestMapping("/give")
@Slf4j
public class GiveController {

    @Autowired
    private GiveService giveService;

    @PostMapping("/create")
    public Result create(@RequestBody GiveDTO giveDTO) {
        log.info("添加赠品:{}", JSON.toJSONString(giveDTO));
        return giveService.create(giveDTO);
    }

    @PostMapping("/update")
    public Result modify(@RequestBody GiveDTO giveDTO) {
        log.info("修改赠品:{}", JSON.toJSONString(giveDTO));
        return giveService.modify(giveDTO);
    }

    @PostMapping("/pageList")
    public Result pageList(@RequestBody GivePageDTO givePageDTO){
        log.info("pageList:{}", JSON.toJSONString(givePageDTO));
        return giveService.pageList(givePageDTO);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id){
        return giveService.delete(id);
    }

    @GetMapping("/find-all")
    public Result findGiveAll(){
        return Result.success(giveService.list());
    }
}
